package top.deepdesigner.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.deepdesigner.dto.CommentReplyDTO;
import top.deepdesigner.pojo.DtsComment;
import top.deepdesigner.service.DtsCommentService;

import java.util.Date;
import java.util.List;

/**
 * Start up <br/>
 * Created with IntelliJ IDEA. <br/>
 * Project Name: shop_manage <br/>
 * Author: duanruiqing <br/>
 * DateTime: 2022/9/24 星期六 14:32:15 <br/>
 */
@Service
public class DtsCommentServiceImpl extends ServiceImpl<BaseMapper<DtsComment>, DtsComment> implements DtsCommentService {
  @Override
  public Long getCommentCount() {
    return this.count(new LambdaQueryWrapper<DtsComment>()
        .eq(DtsComment::getDeleted, false));
  }

  @Override
  public List<DtsComment> getCommentList(Integer page, Integer limit, String sort, String order, Integer userId, Integer valueId) {
    QueryWrapper<DtsComment> wrapper = new QueryWrapper<>();
    wrapper
        .eq("deleted", 0)
        .eq(userId != null, "user_id", userId)
        .eq(valueId != null, "value_id", valueId)
        .orderBy(true, "asc".equalsIgnoreCase(order), sort);
    return this.page(new Page<>(page, limit), wrapper).getRecords();
  }

  @Override
  @Transactional
  public Boolean deleteComment(DtsComment dtsComment) {
    dtsComment.setDeleted(true);
    dtsComment.setUpdateTime(new Date());
    return this.update(dtsComment, new LambdaUpdateWrapper<DtsComment>()
        .eq(DtsComment::getId, dtsComment.getId()));
  }

  @Override
  @Transactional
  public Boolean replyComment(CommentReplyDTO commentReplyDTO) {
    //LambdaQueryWrapper<DtsComment> wrapper = new LambdaQueryWrapper<>();
    //wrapper.eq(DtsComment::getId, commentReplyDTO.getCommentId());
    //DtsComment dtsComment = new DtsComment();
    System.out.println("我回复了" + commentReplyDTO.getCommentId() + ":" + commentReplyDTO.getContent());
    return true;
  }


}
